home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / lib / Option.sig < prev    next >
Encoding:
Text File  |  1997-08-18  |  1.4 KB  |  39 lines  |  [TEXT/Moml]

  1. (* Option -- SML Basis Library *)
  2.  
  3. exception Option
  4.  
  5. val getOpt         : 'a option * 'a -> 'a 
  6. val isSome         : 'a option -> bool 
  7. val valOf          : 'a option -> 'a 
  8. val filter         : ('a -> bool) -> 'a -> 'a option 
  9. val map            : ('a -> 'b) -> 'a option -> 'b option
  10. val join           : 'a option option -> 'a option
  11. val compose        : ('a -> 'b) * ('c -> 'a option) -> ('c -> 'b option)
  12. val mapPartial     : ('a -> 'b option) -> ('a option -> 'b option)
  13. val composePartial : ('a -> 'b option) * ('c -> 'a option) -> ('c -> 'b option)
  14.  
  15. (* 
  16.    [getOpt (xopt, d)] returns x if xopt is SOME x; returns d otherwise.
  17.  
  18.    [isSome vopt] returns true if xopt is SOME x; returns false otherwise.
  19.  
  20.    [valOf vopt] returns x if xopt is SOME x; raises Option otherwise.
  21.  
  22.    [filter p x] returns SOME x if p x is true; returns NONE otherwise.
  23.  
  24.    [map f xopt] returns SOME (f x) if xopt is SOME x; returns NONE otherwise.
  25.  
  26.    [join xopt] returns x if xopt is SOME x; returns NONE otherwise.
  27.  
  28.    [compose (f, g) x] returns SOME (f y) if g x is SOME y; returns NONE 
  29.    otherwise.  It holds that compose (f, g) = map f o g.
  30.  
  31.    [mapPartial f xopt] returns f x if xopt is SOME x; returns NONE otherwise.  
  32.    It holds that mapPartial f = join o map f.
  33.  
  34.    [composePartial (f, g) x] returns f y if g x is SOME y; returns NONE 
  35.    otherwise.  It holds that composePartial (f, g) = mapPartial f o g.
  36.  
  37.    The operators (map, join, SOME) form a monad.
  38. *)
  39.